import * as index from '@/api/index.js'
export default {
	data() {
		return {
			list: [],
			current: 0,
			id: '',
			use_coupon: '',
			loading:false
		}
	},

	onShow() {

	},
	onLoad(option) {
		this.getMyCoupon()
		this.use_coupon = option.use_coupon
	},

	methods: {
		getMyCoupon() {
			this.loading = false
			index.getMyCoupon().then(res => {
				if (this.use_coupon == 'yes') {
					this.list = res.data
					this.id = this.list[this.current].id
				} else {
					res.data.forEach(item => {
						if (item.type == 'shop') {
							this.list.push(item)
						}
					})
					this.id = this.list[this.current].id
				}
				this.loading = true
			})
		},
		currentChange(item, index) {
			this.id = item.id
			this.current = index
		},
		submit() {
			uni.$emit('coupon', {
				id: this.id
			})
			this.$tools.back(1)
		}
	}
}